package cn.rdq.iknesssystem.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.rdq.api.po.Episode;
import cn.rdq.api.po.EpisodeSrc;
import cn.rdq.api.vo.EpisodeSrcVo;
import cn.rdq.dao.EpisodeMapper;
import cn.rdq.dao.EpisodesrcMapper;
import cn.rdq.iknesssystem.service.EpisodeService;
import cn.rdq.iknesssystem.service.EpisodeSrcService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class EpisodeSrcServiceImpl extends ServiceImpl<EpisodesrcMapper, EpisodeSrc> implements EpisodeSrcService {
    @Override
    public List<EpisodeSrc> listEpisode(EpisodeSrcVo episodeSrcVo) {
        QueryWrapper<EpisodeSrc> wrapper = new QueryWrapper<>();
        if (ObjectUtil.isNotEmpty(episodeSrcVo.getEpisodeId())) {
            wrapper.eq("episode_id", episodeSrcVo.getEpisodeId());
        }
        return list(wrapper);
    }

    @Override
    public void deleteById(Long id) {
        removeById(id);
    }

    @Override
    public void deleteByEpisodeId(Long episodeId) {
        QueryWrapper<EpisodeSrc> wrapper = new QueryWrapper<>();
        wrapper.eq("episode_id", episodeId);
        remove(wrapper);
    }

    @Override
    public void saveEpisodeSrc(EpisodeSrc episodeSrc) {
        episodeSrc.setUpdateTime(new Date());
        episodeSrc.setUpdateTime(new Date());
        save(episodeSrc);
    }
}
